package com.xue.web.utils;

/**
 * 加密工具
 */
public class EncryptionUtil {
    /**
     * 解密算法
     * @param Encryption_String
     * @return
     */
    //Encryption_String 加密后的字符串
    public  static String decrypt(String Encryption_String){
        StringBuilder password = new StringBuilder();

        // 自己理解为秘钥和加密串
        String Secret_key = "RDpbLfCPsJZ7fiv";
        String Encrypted_string = "yLwVl0zKqws7LgKPRQ84Mdt708T1qQ3Ha7xv3H7NyU84p21BriUWBU43odz3iP4rBL3cD02KZciXTysVXiV8ngg6vL48rPJyAUw0HurW20xqxv9aYb4M9wK1Ae0wlro510qXeU07kV57fQMc8L6aLgMLwygtc0F10a0Dg70TOoouyFhdysuRMO51yY5ZlOZZLEal1h0t9YQW0Ko7oBwmCAHoic4HYbUyVeU3sfQ1xtXcPcf1aT303wAQhv66qzW";
        char a1;

        // 如果用户输入的登录密码长度小于等于秘钥长度，则按照秘钥来解析
        if (Encryption_String.length() == Secret_key.length()) {
            System.out.println("是根据秘钥来生成的加密后的密码");
            int l, j;
            int isok = 0;
            for (l = 0; l < Secret_key.length(); l++) {
                String temp = "";
                isok = 0;
                for (j = 0; j < Encrypted_string.length(); j++) {
                    if (Encrypted_string.charAt(j) == Encryption_String.charAt(l)) {

                        if ((j ^ Secret_key.charAt(l)) > 33 && (j ^ Secret_key.charAt(l)) < 126) {
                            temp += (char) (j ^ Secret_key.charAt(l));
                            isok = 1;
                        }
                    }
                }
                if (isok == 0) {
                    break;
                }
                password.append(temp);
            }
        } else {
            System.out.println("密码超过15位该方法无法破解");
        }
        return password.toString();
    }

}
